

<template>
  <transition name="el-zoom-in-center">
    <div class="JNPF-preview-main">
      <div class="JNPF-common-page-header">
        <el-page-header @back="goBack()" :content="title" />
      </div>

      <el-row class="JNPF-common-search-box" :gutter="16">
        <el-form @submit.native.prevent>
          <el-col :span="6">
            <!-- <el-form-item label="操作人">
              <el-input v-model="query.taskid" placeholder="请输入" clearable>
              </el-input>
            </el-form-item> -->
            <el-form-item label="操作人">
              <user-select
                v-model="query.creatoruserid"
                placeholder="请选择"
                clearable
              >
              </user-select>
            </el-form-item>
          </el-col>

          <el-col :span="6">
            <el-form-item label="操作动作">
              <el-input v-model="query.operate" placeholder="请输入" clearable>
              </el-input>
            </el-form-item>
          </el-col>

          <el-col :span="12" style="align:left">
            <el-form-item>
              <el-button type="primary" icon="el-icon-search" @click="search()"
                >查询</el-button
              >
              <el-button icon="el-icon-refresh-right" @click="reset()"
                >重置</el-button
              >
              <!-- <el-button icon="el-icon-download" @click="exportData()"
                >导出</el-button
              > -->
              <!-- <el-button
                type="text"
                icon="el-icon-arrow-down"
                @click="showAll = true;btnSpan=24;"
                v-if="!showAll"
              >
                展开
              </el-button>
              <el-button
                type="text"
                icon="el-icon-arrow-up"
                @click="showAll = false;btnSpan=6;"
                v-else
              >
                收起
              </el-button> -->
            </el-form-item>
          </el-col>
        </el-form>
      </el-row>

        <div class="JNPF-common-layout-center">
          <div class="JNPF-common-layout-main JNPF-flex-main">
            <JNPF-table
          v-loading="listLoading"
          :data="list"
          @sort-change="sortChange"
        >
          <!-- <el-table-column
            prop="taskid"
            label="督办任务ID"
            width="0"
            align="left"
          /> -->
          <el-table-column
            prop="operate"
            label="操作动作"
            width="0"
            align="left"
          />
          <el-table-column
            prop="operatoruserid"
            label="执行人"
            width="0"
            align="left"
          />
          <el-table-column
            prop="operatortime"
            label="操作时间"
            width="0"
            align="left"
          />
          <!-- <el-table-column
            prop="operatoruserid"
            label="操作人员"
            width="0"
            align="left"
          /> -->
          <el-table-column
            prop="creatoruserid"
            label="操作人员"
            width="0"
            align="left"
          />
          <!-- <el-table-column
            prop="creatortime"
            label="创建时间"
            width="0"
            align="left"
          /> -->
          <!-- <el-table-column label="操作" fixed="right" width="150">
            <template slot-scope="scope">
              <el-button type="text" @click="addOrUpdateHandle(scope.row.id)"
                >编辑
              </el-button>
              <el-button
                type="text"
                class="JNPF-table-delBtn"
                @click="handleDel(scope.row.id)"
                >删除
              </el-button>
              <el-button type="text" @click="goDetail(scope.row.id)"
                >详情
              </el-button>
            </template>
          </el-table-column> -->
        </JNPF-table>
            <pagination
              :total="total"
              :page.sync="listQuery.currentPage"
              :limit.sync="listQuery.pageSize"
              @pagination="initData"
            />
          </div>
        </div>
      <ExportBox v-if="exportBoxVisible" ref="ExportBox" @download="download"/>
    </div>


  </transition>
</template>




<script>
import request from "@/utils/request";
import { getDictionaryDataSelector } from "@/api/systemData/dictionary";
import JNPFForm from "./Form";
import ExportBox from "./ExportBox";
import { getDataInterfaceRes } from "@/api/systemData/dataInterface";
import Detail from "./Detail";

export default {
  components: { JNPFForm, ExportBox, Detail },
  data() {
    return {
      title: "任务操作日志",
      detailVisible: false,
      query: {
        taskid: undefined,
        creatoruserid:"",
        operate:"",
      },
      treeProps: {
        children: "children",
        label: "fullName",
        value: "id",
      },
      list: [],
      listLoading: true,
      total: 0,
      taskId:"",
      listQuery: {
        currentPage: 1,
        pageSize: 20,
        sort: "desc",
        sidx: "creatortime",
      },
      formVisible: false,
      exportBoxVisible: false,
      columnList: [
        { prop: "taskid", label: "督办任务ID" },
        { prop: "operate", label: "操作动作" },
        { prop: "operatortime", label: "操作时间" },
        { prop: "operatoruserid", label: "操作人员" },
        { prop: "creatoruserid", label: "创建用户" },
        { prop: "creatortime", label: "创建时间" },
      ],
    };
  },
  computed: {
    menuId() {
      return this.$route.meta.modelId || "";
    },
  },
  created() {
    // this.initData();
  },
  methods: {
    goDetail(id) {
      this.detailVisible = true;
      this.$nextTick(() => {
        this.$refs.Detail.init(id);
      });
    },
    sortChange({ column, prop, order }) {
      this.listQuery.sort = order == "ascending" ? "asc" : "desc";
      this.listQuery.sidx = !order ? "" : prop;
      this.initData();
    },

    // 初始化查询参数值并查询数据
    initLoad(taskId) {
      this.query.taskid = taskId;
      this.taskId = taskId;
      this.initData();
    },

    initData() {
      this.listLoading = true;
      let _query = {
        ...this.listQuery,
        ...this.query,
        menuId: this.menuId,
      };
      request({
        url: `/api/example/BusTaskLog/getList`,
        method: "post",
        data: _query,
      }).then((res) => {
        var _list = [];
        for (let i = 0; i < res.data.list.length; i++) {
          let _data = res.data.list[i];
          _list.push(_data);
        }
        this.list = _list;
        this.total = res.data.pagination.total;

        this.listLoading = false;
      });
    },
    handleDel(id) {
      this.$confirm("此操作将永久删除该数据, 是否继续?", "提示", {
        type: "warning",
      })
        .then(() => {
          request({
            url: `/api/example/BusTaskLog/${id}`,
            method: "DELETE",
          }).then((res) => {
            this.$message({
              type: "success",
              message: res.msg,
              onClose: () => {
                this.initData();
              },
            });
          });
        })
        .catch(() => {});
    },
    addOrUpdateHandle(id, isDetail) {
      this.formVisible = true;
      this.$nextTick(() => {
        this.$refs.JNPFForm.init(id, isDetail);
      });
    },
    exportData() {
      this.exportBoxVisible = true;
      this.$nextTick(() => {
        this.$refs.ExportBox.init(this.columnList);
      });
    },
    download(data) {
      let query = {
        ...data,
        ...this.listQuery,
        ...this.query,
        menuId: this.menuId,
      };
      request({
        url: `/api/example/BusTaskLog/Actions/Export`,
        method: "GET",
        data: query,
      }).then((res) => {
        if (!res.data.url) return;
        this.jnpf.downloadFile(res.data.url);
        this.$refs.ExportBox.visible = false;
        this.exportBoxVisible = false;
      });
    },
    search() {
      this.listQuery = {
        currentPage: 1,
        pageSize: 20,
        sort: "desc",
        sidx: "creatortime",
      };
      this.initData();
    },
    refresh(isrRefresh) {
      this.formVisible = false;
      if (isrRefresh) this.reset();
    },
    reset() {
      for (let key in this.query) {
        this.query[key] = undefined;
      }
      this.query.taskid = this.taskId;
      this.search();
    },
    goBack() {
      this.$emit("refresh", false);
    },
  },
};
</script>
